/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package db.dbTables;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import core.objects.BaseObject;
import core.objects.City;

public class CityTable extends AbstractDBTable {

    public static final String COLUMN_ID = "city_id";
    public static final String COLUMN_COUNTRY_ID = "country_id";
    final public DbColumn id = new DbColumn(COLUMN_ID, Types.INTEGER, 11, false, this);
    final public DbColumn cityName = new DbColumn(COLUMN_NAME, Types.VARCHAR, 90, false, this);
    final public DbColumn countryId = new DbColumn(COLUMN_COUNTRY_ID, Types.INTEGER, 11, true, this);

    public CityTable() {
        super("city");
        setIDColumn(id);
    }

    @Override
    public List<DbColumn> getDbColumns() {
        List<DbColumn> list = new ArrayList<DbColumn>();
        list.add(id);
        list.add(cityName);
        list.add(countryId);
        return list;
    }

    @Override
    public BaseObject convertSqlTableToBaseObject(ResultSet resultSet) {
        int id = 0;
        String name = "";

        try {
            id = resultSet.getInt(COLUMN_ID);
            name = resultSet.getString(COLUMN_NAME);
        } catch (SQLException ex) {
            Logger.getLogger(CityTable.class.getName()).log(Level.SEVERE, null, ex);
        }

        return new City(id, name);
    }
}
